package testes;
import java.io.File;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;

import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

/**
 *
 * @author Administrator
 */
public class JDOMTreeExample extends JFrame {

    /** Creates a new instance of JDOMTree */
    public JDOMTreeExample() {
        super("tree");

        Document document = new Document();
        Element root = new Element("root");
        Element child1 = new Element("child1");
        Element child2 = new Element("child2");
        Element grandchild1 = new Element("grandchild1");

        Attribute att = new Attribute("test", "1");
        child1.setAttribute(att);
        child1.addContent(grandchild1);
        root.addContent(child1);
        root.addContent(child2);
        document.setRootElement(root);

        
        
        JDOMTreeModel treeModel = new JDOMTreeModel(getDocument());
        JTree tree = new JTree(treeModel);

        getContentPane().add(new JScrollPane(tree));

        setSize(500,500);
        
    }
    
    public static Document getDocument(){
		SAXBuilder builder = new SAXBuilder();
		Document doc = null;
		try {
			doc = builder.build("meta.script.tropico_ra.xml");
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return doc;
    }

    public static void main(String[] args) {
        JDOMTreeExample example = new JDOMTreeExample();
        example.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        example.setVisible(true);
    }

}